package com.his.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.his.commons.core.exception.HisException;
import com.his.commons.web.util.WebBeanUtils;
import com.his.controller.info.DepartmentInfo;
import com.his.controller.info.DisagnosisRoomInfo;
import com.his.mapper.DepartmentMapper;
import com.his.model.DisagnosisRoom;
import com.his.mapper.DisagnosisRoomMapper;
import com.his.service.DepartmentService;
import com.his.service.DisagnosisRoomService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.util.StringToTrimUtil;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 梅津铧
 * @since 2022-03-22
 */
@Service
public class DisagnosisRoomServiceImpl extends ServiceImpl<DisagnosisRoomMapper, DisagnosisRoom> implements DisagnosisRoomService {

    @Resource
    private DisagnosisRoomMapper disagnosisRoomMapper;
    @Resource
    private DepartmentService departmentService;

    /**
     * 根据科室id获取下属诊室信息
     *
     * @param departmentId
     */
    @Override
    public List<DisagnosisRoomInfo> obtainDisRoom(Integer departmentId) throws HisException {
        if(!StringToTrimUtil.StringToTrim(String.valueOf(departmentId))) throw new HisException("请输入正确信息",500);

        DepartmentInfo departmentInfo = departmentService.obtainByCondition(String.valueOf(departmentId));
        if(null == departmentInfo) throw new HisException("该科室不存在",500);

        if(departmentInfo.getDepartmentState().equals("否")) throw new HisException("此科室无下属诊室",500);
        List<DisagnosisRoom> disagnosisRooms = disagnosisRoomMapper.selectList(new QueryWrapper<DisagnosisRoom>().eq("department_id", departmentId));
        if(null == disagnosisRooms) throw new HisException("未查询到",500);
        List<DisagnosisRoomInfo> disagnosisRoomInfos = WebBeanUtils.copyList(disagnosisRooms, DisagnosisRoomInfo.class);

        return disagnosisRoomInfos;
    }
}
